class ZJHGameView extends how.module.Scene 
{
    public tableCard: eui.Group;
    public qipaiArea: eui.Group;
    public lookCardButton: eui.Button;
    public effectArea: eui.Group;
    public handCardPanel: eui.Group;
    public gameEffectPanel: ZJHGameEffectPanel;//特效面板
    public zhuLabel: how.Label;
    public lunLabel: how.Label;
    public operatePanel: ZJHOperatePanelView;
    public choumaArea: eui.Group;
    public jiangchiLabel: how.Label;
    public jiangchiGroup: eui.Group;
    public settingButton: how.Button;
    public backButton: how.Button;
    public constructor() 
    {
        super();
        this.skinName = "ZJHGameSkin";
        this.gameEffectPanel.tableCard = this.tableCard;
        this.gameEffectPanel.handCardPanel = this.handCardPanel;
        this.operatePanel.handCardPanel = this.handCardPanel;
        this.operatePanel.qipaiArea = this.qipaiArea;
    }
    public start(): void 
    {
        console.log(">>> ZJHGameView start ");
        this.playTween();
        this.jiangchiGroup.visible = false;
        this.tableCard.visible = false;
        this.qipaiArea.visible = false;
        this.lookCardButton.visible = false;
        for (var i: number = 0; i < 3; i++) {
            this.handCardPanel.getChildAt(i).visible = false;
        }
        this.zhuLabel.visible = false;
        this.lunLabel.visible = false;
        this.operatePanel.visible = false;
        this.lookCardButton.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onLookCardButton, this);
        this.settingButton.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onSettingButton, this);
        this.backButton.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onBackButton, this);
    }
    private playTween(): void {
        this.alpha = 0;
        egret.Tween.get(this).to({ alpha: 1 }, 300);
    }
    /**
     * 当游戏开始
     */
    public onGameStart(data: ZJHGameData): void 
    {
        console.log(">>> ZJHGameView onGameStart 当游戏开始");
        this.tableCard.visible = true;
        this.gameEffectPanel.playStartCardEffect((): void => {
            this.lookCardButton.alpha = 0;
            this.lookCardButton.visible = true;
            egret.Tween.get(this.lookCardButton).to({ alpha: 1 }, 300);
            this.report(ZJHGameModule.request.onStartEffectComplete);
        }, this);
        this.zhuLabel.visible = true;
        this.lunLabel.visible = true;
        var gameData: ZJHGameData = <ZJHGameData>AppData.getInstance().gameData;
        this.zhuLabel.text = how.StringUtils.format(
            LanguageConfig.zhu,
            base.Utils.formatCurrency(gameData.lCellScore),
            base.Utils.formatCurrency(gameData.lMaxScore)
        );
        this.lunLabel.text = how.StringUtils.format(
            LanguageConfig.lun,
            data.roundNum,
            15
        );
        this.jiangchiGroup.visible = true;
        this.jiangchiLabel.text = base.Utils.formatCurrency(data.currentScoreCount);
    }
    public setOperateUI(data: ZJHGameData): void {
        this.jiangchiLabel.text = base.Utils.formatCurrency(data.currentScoreCount);
    }
    /**
     * 当游戏结束
     */
    public onGameEnd(data: ZJHGameData): void 
    {
        console.log(">>> ZJHGameView onGameEnd 当游戏结束");
        this.lookCardButton.visible = false;
        this.jiangchiGroup.visible = false;
        for (var i: number = 0; i < 3; i++) {
            var card: eui.Image = this.handCardPanel.getChildAt(i) as eui.Image;
            card.visible = false;
            card.source = "card_0_png";
        }
    }
    /**
     * 设置轮次
     */
    public setLunciUI(data: any): void 
    {
        console.log(">>> ZJHGameView setLunciUI 设置轮次");
        this.lunLabel.text = how.StringUtils.format(
            LanguageConfig.lun,
            data.roundNum,
            15
        );
    }
    private onLookCardButton(event: egret.TouchEvent): void 
    {
        console.log(">>> ZJHGameView onLookCardButton 点击看牌");
        this.lookCardButton.visible = false;
        this.report("lookCard");
    }
    private onSettingButton(event: egret.TouchEvent): void 
    {
        console.log(">>> ZJHGameView onSettingButton 点击设置");
        this.report(ZJHGameModule.request.onSettingButton);
    }
    private onBackButton(event: egret.TouchEvent): void 
    {
        console.log(">>> ZJHGameView onBackButton 点击返回");
        this.report(ZJHGameModule.request.onBackButton);
    }
    public setCardUI(cardData: number[]): void 
    {
        console.log(">>> ZJHGameView setCardUI 设置牌");
        for (var i: number = 0; i < cardData.length; i++) {
            var card: eui.Image = this.handCardPanel.getChildAt(i) as eui.Image;
            card.source = "card_" + cardData[i] + "_png";
        }
    }
    public setCompareUI(data: any): void
    {
        //"wCurrentUser":65535,"wCompareUser":[3,4],"wLostUser":4
        console.log(">>> ZJHGameView setCompareUI 比牌");
        var users: number[] = data.wCompareUser;//参与比牌的玩家
        var players: ZJHPlayerView[] = [];
        var lostIndex: number;
        for (var i: number = 0; i < users.length; i++) {
            players.push(this["player" + AppData.getInstance().gameData.getSeatID(users[i])]);
            if (users[i] == data.wLostUser) {
                lostIndex = players.length - 1;
            }
        }
        this.gameEffectPanel.playCompareCard(players, lostIndex);
    }
}